package com.htc.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.htc.dao.UserMapper;
import com.htc.model.PageResult;
import com.htc.model.User;
import com.htc.model.request.UserRequest;

@Service
public class UserService {
    @Autowired
	private UserMapper userMapper;


    public User login(User user) {
        List<User> list = userMapper.login(user);
        if(list.size() > 0){
            return list.get(0);
        }else{
            return null;
        }
    }
    
    
    public PageResult<User> queryList(UserRequest request) {
		Page page = PageHelper.startPage(request.getPage(), request.getLimit());
		List<User> list =  userMapper.queryList(request.convertWhereStr());
		return new PageResult<User>(list, page.getTotal(), page.getPageSize(), page.getPageNum());
	}
	
	
	public void add(User user) {
		userMapper.insert(user);
	}
	
	public void update(User user) {
		userMapper.update(user);
	}
	
	public void del(int id) {
		userMapper.del(id);
	}


	public void updatePassword(Integer uuid, String password) {
		userMapper.updatePassword(uuid,password);
	}
	
}
